<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class RbacCreate extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_role', function (Blueprint $table) {
            $table->integer('admin_id')->unsigned()->comment("用户ID");
            $table->integer('role_id')->unsigned()->comment("角色ID");
            $table->primary(['admin_id', 'role_id']);
        });

        Schema::create('rbac_role_resource', function (Blueprint $table) {
            $table->integer('resource_id')->unsigned()->comment("资源ID");
            $table->integer('role_id')->unsigned()->comment("角色ID");
            $table->primary(['role_id', 'resource_id']);
        });

        Schema::create('rbac_resource_uri', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('resource_id')->unsigned()->comment("资源ID");
            $table->string('uri')->default('')->comment("URI") ;
            $table->string('method',50)->default('')->comment("访问方法") ;

        });

        Schema::create('rbac_role', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',50)->unique()->comment("角色名");
        });

        Schema::create('rbac_resource', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('pid')->unsigned()->default(0)->comment("上级资源ID");
            $table->smallInteger('type')->default(0)->comment("类型");;
            $table->string('link')->default('')->comment("链接地址"); ;
            $table->string('code',50)->unique()->comment("标识符");;
            $table->string('name',50)->comment("资源名称");;
        });


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_role');
        Schema::dropIfExists('rbac_role_resource');
        Schema::dropIfExists('rbac_resource_uri');
        Schema::dropIfExists('rbac_role');
        Schema::dropIfExists('rbac_resource');
    }
}
